//
//  MWSearchCell.m
//  XiRan-iOS
//
//  Created by liuyiming on 2019/11/24.
//  Copyright © 2019 Wood. All rights reserved.
//

#import "MWSearchCell.h"

@interface MWSearchCell ()

@property (nonatomic, strong) UIView *backView;
@property (nonatomic, strong) UILabel *titleLB;

@end

@implementation MWSearchCell

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self setupPageSubviews];
    }
    return self;
}

- (void)setTitle:(NSString *)title {
    _titleLB.text = title;
}

+ (CGSize)getSizeWithText:(NSString*)title {
    NSMutableParagraphStyle* style = [[NSMutableParagraphStyle alloc] init];
    style.lineBreakMode = NSLineBreakByCharWrapping;
    NSDictionary *attrDic = @{NSFontAttributeName:[UIFont systemFontOfSize:12.0f],NSParagraphStyleAttributeName:style};
    CGSize size = [title boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, 28) options:NSStringDrawingUsesLineFragmentOrigin attributes:attrDic context:nil].size;
    if (size.width + 2 * 10 >= [UIScreen mainScreen].bounds.size.width - 2 * 16) {
        size.width = [UIScreen mainScreen].bounds.size.width - 2 * 10 - 2 * 16;
    }
    return CGSizeMake(ceilf(size.width + 2 * 10), 28);
}

- (void)setupPageSubviews {
    _titleLB = [[UILabel alloc] init];
    _titleLB.backgroundColor = MWHexColor(@"#F6F7FB");
    _titleLB.textAlignment = NSTextAlignmentCenter;
    _titleLB.layer.cornerRadius = 14;
    _titleLB.layer.masksToBounds = YES;
    _titleLB.font = MWFont(12);
    _titleLB.textColor = MWHexColor(@"#333333");
    _titleLB.text = @"1234";
    [self.contentView addSubview:_titleLB];
    
    [_titleLB mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.contentView);
    }];
}

@end
